package yqt.com.cnki.service.impl;


import haha.life.common.CutPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yqt.com.cnki.bo.QKYDBo;
import yqt.com.cnki.dao.IQKYDDao;
import yqt.com.cnki.po.KeyValuePo;
import yqt.com.cnki.po.QKYDPo;
import yqt.com.cnki.service.IQKYDService;

import java.util.List;

/**
 * Description:
 *
 * @author BaiGe
 * @date: 2021/11/12 14:31
 * @Version 1.0
 */
@Service
public class QKYDServiceImpl implements IQKYDService {
    @Autowired
    private IQKYDDao qkydDao;

    @Override
    public List<QKYDPo> getQKYD_Index() {
        List<QKYDPo> qkydList = qkydDao.getQKYD_Index();
        return qkydList;
    }

    @Override
    public List<KeyValuePo> getYear_Chinese() {
        return qkydDao.getYear_Chinese();
    }

    @Override
    public List<KeyValuePo> getSort_English() {
        return qkydDao.getSort_English();
    }

    @Override
    public CutPageBean<QKYDPo> complexSearchQKYD(QKYDBo qkydBo) {
        String[] yearArr = qkydBo.getYearArr();
        String[] sortArr = qkydBo.getSortArr();
        StringBuffer yearArrBuff = new StringBuffer();
        StringBuffer sortArrBuff = new StringBuffer();
        if (sortArr != null && sortArr.length > 0) {
            for (int i = 0; i < sortArr.length; i++) {
                sortArrBuff.append("分类 =\"").append(sortArr[i]).append("*\"").append(" or ");
            }
            if (sortArrBuff.length() > 3) {
                String sortArrStr = sortArrBuff.substring(0, sortArrBuff.length() - 3);
                qkydBo.setSortArrStr(sortArrStr);
            }
        }

        if (yearArr != null && yearArr.length > 0) {
            for (int i = 0; i < yearArr.length; i++) {
                yearArrBuff.append("年 =").append(yearArr[i]).append(" or ");
            }
            if (yearArrBuff.length() > 3) {
                String yearArrStr = yearArrBuff.substring(0, yearArrBuff.length() - 3);
                qkydBo.setYearArrStr(yearArrStr);
            }
        }
        qkydBo.setStart(qkydBo.getPage(), qkydBo.getPageSize());
        CutPageBean<QKYDPo> cutPageBean = new CutPageBean();
        List<QKYDPo> qkydList = qkydDao.complexSearchQKYD_List(qkydBo);
        int count = (int) qkydDao.complexSearchQKYD_Count(qkydBo);
        cutPageBean.initCutPage(count, qkydBo.getPageSize(), qkydList);
        return cutPageBean;
    }


    @Override
    public QKYDPo getQKYDPoById(QKYDPo qkydPo) {
        return qkydDao.getQKYDPoById(qkydPo);
    }

    @Override
    public String getQKYDFileBasePath(String dbCode) {
        String realDbCode=dbCode.split("_")[0]+"_DATABASE_DESCRIPT";
        return qkydDao.getQKYDFileBasePath(realDbCode);
    }

    @Override
    public Boolean addBrowseRate(QKYDPo qkydPo) {
        return qkydDao.addBrowseRate(qkydPo);
    }

    @Override
    public Boolean addDownloadRate(QKYDPo qkydPo) {
        return qkydDao.addDownloadRate(qkydPo);
    }
}
